import { reactive } from "vue";
import { getListApi as getAllPaymentApi } from "@/api/configCenter/paymentManagement";
import { getAllCompanyApi, getUserByPositionApi } from "@/api/managementCenter/departmentPersonnel";
// import { getListApi as getCustomerApi } from "@/api/managementCenter/customerManagement";
import { getAllCustomerApi } from "@/api/common";
export const searchItemList: Array<SuperSearch.SearchItem> = [
  {
    type: "input",
    label: "运单号",
    keyName: "waybillNums",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  {
    type: "input",
    label: "对账单号",
    keyName: "billNums",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  // {
  //   type: "input",
  //   label: "客户简称",
  //   keyName: "customerNames",
  //   placeholder: "支持批量(空格/逗号隔开)"
  // },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "客户简称",
    keyName: "customerIdList",
    optionsRequest: getAllCustomerApi,
    optReqParams: { isFilterChild: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    attrs: {
      mode: "multiple"
    },
    optConfig: {
      label: "shortName",
      value: "id"
    },
    options: []
  }),
  {
    type: "select",
    label: "核销状态",
    keyName: "stateList",
    optConfig: {
      label: "name",
      value: "code"
    },
    attrs: {
      mode: "multiple"
    },
    options: [
      {
        name: "未核销",
        code: 0
      },
      {
        name: "部分核销",
        code: 1
      },
      {
        name: "已核销",
        code: 2
      },
      {
        name: "已撤回",
        code: 3
      }
    ]
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "业务员",
    keyName: "bizIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "4", status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "账期",
    keyName: "accountPeriodIdList",
    optionsRequest: getAllPaymentApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "accountName",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "出账人",
    keyName: "createByList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },

    options: []
  }),
  {
    type: "datetimerange",
    label: "出账时间",
    keyName: "createTime"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "经营单位",
    keyName: "companyIdList",
    optionsRequest: getAllCompanyApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "name",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },

    options: []
  })
];

export const tableColumnMap: Base.GeneraDataType<Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem>> = {
  0: [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50",
      fixed: "left"
    },
    {
      field: "billNum",
      title: "对账单号",
      minWidth: "150",
      renderSlot: "billNum"
    },
    {
      field: "state",
      title: "核销状态",
      minWidth: "100",
      renderSlot: "state"
    },
    {
      field: "shipmentCount",
      title: "运单数",
      minWidth: "120"
    },
    {
      field: "customerName",
      title: "客户简称",
      minWidth: "120",
      sortable: true
    },
    {
      field: "companyName",
      title: "客户名称",
      minWidth: "120"
    },
    {
      field: "price",
      title: "账单金额",
      minWidth: "100"
    },
    {
      field: "chargeOffPrice",
      title: "已核销金额",
      minWidth: "100"
    },
    {
      field: "unChargeOffPrice",
      title: "未核销金额",
      minWidth: "100"
    },
    {
      field: "remark",
      title: "账单备注",
      minWidth: "140"
    },
    {
      field: "bizName",
      title: "业务员",
      minWidth: "90"
    },
    {
      field: "accountName",
      title: "账期",
      minWidth: "90"
    },
    {
      field: "createName",
      title: "出账人",
      minWidth: "80",
      sortable: true
    },
    {
      field: "createTime",
      title: "出账时间",
      minWidth: "135",
      formatter: "formatDate",
      sortable: true
    },
    // {
    //   field: "updateName",
    //   title: "核销人",
    //   minWidth: "80"
    // },
    // {
    //   field: "updateTime",
    //   title: "核销时间",
    //   minWidth: "135",
    //   formatter: ({ cellValue }: any) => {
    //     if (cellValue) return dayjs(Number(cellValue)).format("YYYY-MM-DD HH:mm:ss");
    //     else return "-";
    //   }
    // },
    {
      field: "companyName2",
      title: "经营单位",
      minWidth: "80"
    },
    {
      field: "action",
      title: "操作",
      minWidth: "235",
      fixed: "right",
      renderSlot: "action"
    }
  ],
  1: [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50",
      fixed: "left"
    },
    {
      field: "billNum",
      title: "对账单号",
      minWidth: "150",
      renderSlot: "billNum"
    },
    {
      field: "state",
      title: "核销状态",
      minWidth: "100",
      renderSlot: "state"
    },
    {
      field: "shipmentCount",
      title: "运单数",
      minWidth: "120"
    },
    {
      field: "customerName",
      title: "客户简称",
      minWidth: "120",
      sortable: true
    },
    {
      field: "companyName",
      title: "客户名称",
      minWidth: "120"
    },
    {
      field: "price",
      title: "账单金额",
      minWidth: "100"
    },
    {
      field: "chargeOffPrice",
      title: "已核销金额",
      minWidth: "100"
    },
    {
      field: "unChargeOffPrice",
      title: "未核销金额",
      minWidth: "100"
    },
    {
      field: "remark",
      title: "账单备注",
      minWidth: "140"
    },
    {
      field: "bizName",
      title: "业务员",
      minWidth: "90"
    },
    {
      field: "accountName",
      title: "账期",
      minWidth: "90"
    },
    {
      field: "createName",
      title: "出账人",
      minWidth: "80",
      sortable: true
    },
    {
      field: "createTime",
      title: "出账时间",
      minWidth: "135",
      formatter: "formatDate",
      sortable: true
    },
    // {
    //   field: "updateName",
    //   title: "核销人",
    //   minWidth: "80"
    // },
    // {
    //   field: "updateTime",
    //   title: "核销时间",
    //   minWidth: "135",
    //   formatter: ({ cellValue }: any) => {
    //     if (cellValue) return dayjs(Number(cellValue)).format("YYYY-MM-DD HH:mm:ss");
    //     else return "-";
    //   }
    // },
    {
      field: "companyName2",
      title: "经营单位",
      minWidth: "80"
    },
    {
      field: "action",
      title: "操作",
      minWidth: "160",
      fixed: "right",
      renderSlot: "action"
    }
  ]
};
// 统计
export const statisticsColumn: Array<{ field: string; label: string }> = [
  {
    label: "帐单数",
    field: "receivableBillNumber"
  },
  {
    label: "账单金额合计",
    field: "receivableBillTotalPrice"
  },
  {
    label: "未核销金额合计",
    field: "unChargeOffTotalPrice"
  }
];
